/***********************************************************************
 * Module:  Comment.java
 * Author:  Voja
 * Purpose: Defines the Class Comment
 ***********************************************************************/

package model.entity;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "comment")
public class Comment implements Serializable{

	private static final long serialVersionUID = 7671471316019248115L;

	@Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "comment_id", unique = true, nullable = false)
    private Integer id;
   
    @Column(name = "comment_title", unique = false, nullable = true)
    private String title;
   
    @Column(name = "comment_contents", unique = false, nullable = true)
    private String contents;
   
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "comment_date", unique = false, nullable = true)
    private Date date;
   
    @ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name = "photo_id", referencedColumnName = "photo_id", nullable = false)
    private Photo photo;
   
    @ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false)
    private User user;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContents() {
		return contents;
	}

	public void setContents(String contents) {
		this.contents = contents;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Photo getPhoto() {
		return photo;
	}

	public void setPhoto(Photo photo) {
		this.photo = photo;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@Override
	public String toString() {
		return "Comment [id=" + id + "]";
	}
    
	@Override
	public boolean equals(Object obj) {
		if(!(obj instanceof Comment))
			return false;
		return ((Comment)obj).getId().intValue()==getId().intValue();
	}
}